package com.zy.servlet.order;

import com.zy.service.AddOrderService;
import com.zy.service.impl.AddOrderServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Date;

@WebServlet("/addOrder")
public class AddOrderServlet extends HttpServlet {
    private AddOrderService addOrderService = new AddOrderServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String paymentAmountStr = req.getParameter("paymentAmount");
        String paymentTimeStr = req.getParameter("paymentTime");
        String userIdStr = req.getParameter("userId");

        if (paymentAmountStr != null && paymentTimeStr != null && userIdStr != null) {
            BigDecimal paymentAmount = new BigDecimal(paymentAmountStr);
            Date paymentTime = new Date(Long.parseLong(paymentTimeStr));
            int userId = Integer.parseInt(userIdStr);

            addOrderService.addOrder(paymentAmount, paymentTime, userId);
            resp.setStatus(HttpServletResponse.SC_OK);
        } else {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        }
    }
} 